package com.zonta.finance.serivce.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zonta.finance.config.ObjectConvertor;
import com.zonta.finance.domain.po.DataDictionary;
import com.zonta.finance.domain.vo.DataDictionaryVo;
import com.zonta.finance.enums.DataCodeCateEnum;
import com.zonta.finance.mapper.DataDictionaryMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zonta.finance.serivce.IDataDictionaryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author zonta
 * @since 2024-07-29
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class DataDictionaryServiceImpl extends ServiceImpl<DataDictionaryMapper, DataDictionary> implements IDataDictionaryService {

    private final ObjectConvertor objectConvertor;
    /**
     * 查询行业数据
     * @return
     */
    @Override
    public List<DataDictionaryVo> listHangYe() {
        List<DataDictionary> data = listByDataTypeCode(DataCodeCateEnum.HANG_YE.getCode());
        return objectConvertor.toDataDictionaryVo(data);
    }

    /**
     *查看会计准则数据字典列表
     * @return
     */
    @Override
    public List<DataDictionaryVo> listKuaiJiZhunZe() {
        List<DataDictionary> data = listByDataTypeCode(DataCodeCateEnum.KUAI_JI_ZHUN_ZE.getCode());
        return objectConvertor.toDataDictionaryVo(data);
    }

    /**
     * 更加数据字典类别查看数据字典
     * @param dataCodeCate
     * @return
     */
    private List<DataDictionary> listByDataTypeCode(String dataCodeCate) {
        LambdaQueryWrapper<DataDictionary> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(DataDictionary::getId,DataDictionary::getDataCode,DataDictionary::getDataValue);
        wrapper.eq(DataDictionary::getDataCodeCate,dataCodeCate);
        return list(wrapper);
    }
}
